//
//  AddAndCutView.m
//  AmountBody
//
//  Created by smm on 2018/1/26.
//  Copyright © 2018年 RCMTM. All rights reserved.
//

#import "AddAndCutView.h"

@implementation AddAndCutView

-(instancetype)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        
    }
    return self;
}
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initSubViews];
    }
    return self;
}
-(void)initSubViews
{
    _bg_image = [[UIImageView alloc]init];
    [self addSubview:_bg_image];
    _bg_View = [[UIView alloc]init];
    [_bg_image addSubview:_bg_View];
    _addButton = [[UIButton alloc]init];
    [_bg_View addSubview:_addButton];
    _cutButton = [[UIButton alloc]init];
    [_bg_View addSubview:_cutButton];
    _countText = [[UITextField alloc]init];
    [_bg_View addSubview:_countText];
    
}
-(void)loadAddAndCutView
{
    CGFloat imageW = self.frame.size.width;
    CGFloat imageH  =self.frame.size.height;
    _bg_image.frame = CGRectMake(0, 0, imageW, imageH);
    _bg_image.image = [UIImage imageNamed:@"countBg"];
    _bg_image.userInteractionEnabled = YES;
    CGFloat jianGe = 5;
    _bg_View.frame = CGRectMake(jianGe, jianGe, imageW-jianGe*2, imageH-jianGe*2);
    [_bg_View setYuanJiaoForRadius:5.0 andMasks:NO];
    CGFloat buttonW = _bg_View.frame.size.width/3.0+5;
    CGFloat textW = _bg_View.frame.size.width/3.0-10;
    CGFloat buttonH = imageH-jianGe*2;
    _cutButton.frame = CGRectMake(0, 0, buttonW, buttonH);
    _cutButton.backgroundColor = [UIColor whiteColor];
    [_cutButton addTarget:self action:@selector(cutButtonFunc:) forControlEvents:UIControlEventTouchUpInside];
    [_cutButton setTitle:@"-" forState:UIControlStateNormal];
    [_cutButton setTitleColor:ZhongZi_Color forState:UIControlStateNormal];
    _countText.frame = CGRectMake(buttonW, 0, textW, buttonH);
    _countText.text = @"1";
    _count = 1;
    _countText.textAlignment = NSTextAlignmentCenter;
    _countText.textColor = RGBColorAlpha(255, 66, 89, 1);
    _addButton.frame = CGRectMake(buttonW+textW, 0, buttonW, buttonH);
    [_addButton addTarget:self action:@selector(addButtonFunc:) forControlEvents:UIControlEventTouchUpInside];
    _addButton.backgroundColor = [UIColor whiteColor];
    [_addButton setTitle:@"+" forState:UIControlStateNormal];
    [_addButton setTitleColor:RGBColorAlpha(45, 45, 45, 1) forState:UIControlStateNormal];
}

-(void)cutButtonFunc:(UIButton*)button
{
    if (_count>1) {
        _count--;
    }
    _countText.text = [NSString stringWithFormat:@"%d",_count];
    NSLog(@"cutButton");
}
-(void)addButtonFunc:(UIButton*)button
{
    _count++;
    _countText.text = [NSString stringWithFormat:@"%d",_count];
    NSLog(@"addButton");
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
